added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBCallNativeDllWrapper / ReadMe.txt
blob8315ada07adf46966f2940328192383805698c06
1 =============================================================================
2       CONSOLE APPLICATION : VBCallNativeDllWrapper Project Overview
3 =============================================================================
5 /////////////////////////////////////////////////////////////////////////////
6 Summary:
8 The code sample demonstrates calling the functions and classes exported by a 
9 native C++ DLL module from VB.NET code through C++/CLI wrapper classes.
11   VBCallNativeDllWrapper (this .NET application)
12           -->
13       CppCLINativeDllWrapper (the C++/CLI wrapper)
14               -->
15           CppDynamicLinkLibrary (a native C++ DLL module)
18 /////////////////////////////////////////////////////////////////////////////
19 Demo:
21 The following steps walk through a demonstration of the .NET-native interop 
22 sample.
24 Step1. After you successfully build the CppDynamicLinkLibrary, 
25 CppCLINativeDllWrapper, and VBCallNativeDllWrapper sample projects in Visual 
26 Studio 2008, you will get the applications: VBCallNativeDllWrapper.exe and 
27 two DLL files: CppCLINativeDllWrapper.dll and CppDynamicLinkLibrary.dll. 
28 Their relationship is that VBCallNativeDllWrapper.exe invokes 
29 CppCLINativeDllWrapper.dll, which further invokes functions and classes 
30 exported by CppDynamicLinkLibrary.dll.
32 Step2. Run VBCallNativeDllWrapper in a command prompt. The application should
33 print the following messages in the console. 
35     Module "CppDynamicLinkLibrary" is loaded
36     GetStringLength1("HelloWorld") => 10
37     GetStringLength2("HelloWorld") => 10
38     Max(2, 3) => 3
39     Class: CSimpleObject::FloatProperty = 1.20
40     Module "CppDynamicLinkLibrary" is loaded
42 The messages indicate that VBCallNativeDllWrapper successfuly loaded 
43 CppDynamicLinkLibrary.dll and invoked the functions (GetStringLength1, 
44 GetStringLength2, Max) and the class (CSimpleObject) exported by the native 
45 module.
47 NOTE: You may receive the following error if you run the debug build of the 
48 sample project on a system without the Visual Studio 2008 installed. 
50     Unhandled Exception: System.IO.FileLoadException: Could not load file or 
51     assembly 'CppCLINativeDllWrapper, Version=1.0.0.0, Culture=neutral, 
52     PublicKeyToken=null' or one of its dependencies. This application has 
53     failed to start because the application configuration is incorrect. 
54     Reinstalling the application may fix this problem. (Exception from 
55     HRESULT: 0x800736B1)
56     File name: 'CppCLINativeDllWrapper, Version=1.0.0.0, Culture=neutral, 
57     PublicKeyToken=null' ---> System.Runtime.InteropServices.COMException 
58     (0x800736B1): This application has failed to start because the application 
59     configuration is incorrect. Reinstalling the application may fix this 
60     problem. (Exception from HRESULT: 0x800736B1)
61        at CSCallNativeDllWrapper.Program.Main(String[] args)
63 This is caused by the fact the debug build of CppCLINativeDllWrapper and 
64 CppDynamicLinkLibrary depends on the Debug CRT which is only available in the 
65 development environments with Visual Studio 2008 installed. You must run the 
66 release build of the sample project in the non-development environment. 
69 /////////////////////////////////////////////////////////////////////////////
70 Sample Relation:
71 (The relationship between the current sample and the rest samples in 
72 Microsoft All-In-One Code Framework http://1code.codeplex.com)
74 VBCallNativeDllWrapper -> CppCLINativeDllWrapper -> CppDynamicLinkLibrary
75 The VB.NET sample application VBCallNativeDllWrapper calls the functions and 
76 classes exported by the native C++ DLL module CppDynamicLinkLibrary through 
77 the C++/CLI wrapper class library CppCLINativeDllWrapper.
80 /////////////////////////////////////////////////////////////////////////////
81 Implementation:
83 Step1. Reference the C++/CLI wrapper class library CppCLINativeDllWrapper in 
84 the VB.NET sample applicatino. CppCLINativeDllWrapper wraps the functions and 
85 classes exported by the native C++ DLL CppDynamicLinkLibrary.
87 Step2. Call the .NET classes CSimpleObjectWrapper and NativeMethods exposed 
88 by CppCLINativeDllWrapper to indirectly access the functions and classes 
89 exported by the native C++ DLL CppDynamicLinkLibrary. For example, 
91     Dim obj As New CSimpleObjectWrapper
92     obj.FloatProperty = 1.2F
93     Dim fProp As Single = obj.FloatProperty
94     Console.WriteLine("Class: CSimpleObject::FloatProperty = {0:F2}", fProp)
97 /////////////////////////////////////////////////////////////////////////////
98 References:
100 How to: Wrap Native Class for Use by C#
101 http://msdn.microsoft.com/en-us/library/ms235281.aspx
104 /////////////////////////////////////////////////////////////////////////////